import multiprocessing as mp

def job(x):
    return x*x

def multicore():
    pool = mp.Pool()
    #Pool(process = 3)表示用3个核
    res = pool.map(job,range(10))
    #map一次多个进程
    print(res)
    res1 = pool.apply_async(job,(2,))
    #2,表示迭代的.但是上面的函数只能输入1个值
    #apply_async一次一个进程
    print(res1.get())
    multi_res1 = [pool.apply_async(job,(i,)) for i in range(10)]
    #想迭代必须这样
    print([res1.get() for res1 in multi_res1])   

if __name__ == "__main__":
    multicore()